import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:get/instance_manager.dart';
import 'package:hotfil_pub_web/pages/home/my_home_page.dart';
import 'package:hotfil_pub_web/pages/message/message_page.dart';
import 'package:hotfil_pub_web/pages/mine/mine_page.dart';
import 'package:hotfil_pub_web/routes/app_pages.dart';

import 'package:get/get.dart';
import 'package:hotfil_pub_web/widgets/bottom_bar_items.dart';
import 'package:hotfil_pub_web/widgets/my_theme.dart';

class DashboardPage extends StatefulWidget {
  @override
  State<DashboardPage> createState() => _DashboardPageState();
}

class _DashboardPageState extends State<DashboardPage> {
  int _currentIndex = 0;
  late PageController _pageController;

  @override
  void initState() {
    super.initState();
    _pageController = PageController();
  }

  @override
  void dispose() {
    _pageController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: SizedBox.expand(
        child: PageView(
          controller: _pageController,
          onPageChanged: (value) {
            _currentIndex = value;
            setState(() {});
          },
          children: <Widget>[
            MyHomePage(),
            Container(
              color: Colors.red,
              child: Center(
                child: ElevatedButton(
                    onPressed: () {
                      Get.toNamed(Routes.MAIN_LOGIN);
                    },
                    child: Text('跳转')),
              ),
            ),
            MessagePage(),
            MinePage(),
          ],
        ),
      ),
      bottomNavigationBar: CupertinoTabBar(
        border: Border(top: BorderSide(color: MyTheme.borderColor)),
        backgroundColor: Colors.white,
        currentIndex: _currentIndex,
        iconSize: 24,
        onTap: (index) {
          setState(() => _currentIndex = index);
          _pageController.jumpToPage(index);
        },
        items: BottomBarItems,
      ),
    );
  }
}
